/*
* Copyright (c) 2014 Qunar.com. All Rights Reserved.
*/
package net.oschina.bilbodai.common.beanutil.property.asm.lexer.code.mp;

import java.util.HashMap;
import java.util.Map;

/**
 * 支持类型：<br>
 * <ul>
 * <li>byte</li>
 * <li>short</li>
 * <li>int</li>
 * <li>long</li>
 * <li>float</li>
 * <li>double</li>
 * <li>string</li>
 * <li>boolean</li>
 * </ul>
 *
 * @author qt-maodai  Date: 15-8-9 Time: 下午1:53
 * @version $Id$
 */
public class MapKeyTypeMapping {
    private static final Map<String, MapKeyType> MAP_VAR_LOAD_TYPE_MAP = new HashMap<String, MapKeyType>();
    private static final Map<Class<?>, String> MAP_TYPE_NAME = new HashMap<>();

    static {
        addType("byte", MapKeyType.ByteType);
        addType("short", MapKeyType.ShortType);
        addType("int", MapKeyType.IntType);
        addType("long", MapKeyType.LongType);
        addType("float", MapKeyType.FloatType);
        addType("double", MapKeyType.DoubleType);
        addType("string", MapKeyType.StringType);
        addType("boolean", MapKeyType.BoolType);

        addTypeName(byte.class, "byte");
        addTypeName(Byte.class, "byte");
        addTypeName(short.class, "short");
        addTypeName(Short.class, "short");
        addTypeName(int.class, "int");
        addTypeName(Integer.class, "int");
        addTypeName(long.class, "long");
        addTypeName(Long.class, "long");
        addTypeName(float.class, "float");
        addTypeName(Float.class, "float");
        addTypeName(double.class, "double");
        addTypeName(Double.class, "double");
        addTypeName(String.class, "string");
        addTypeName(boolean.class, "boolean");
        addTypeName(Boolean.class, "boolean");
    }

    public static String getTypeNameByType(Class<?> type) {
        return MAP_TYPE_NAME.get(type);
    }

    public static MapKeyType getType(String extendTypeString) {

        return MAP_VAR_LOAD_TYPE_MAP.get(extendTypeString);
    }

    private static void addTypeName(Class<?> type, String name) {
        MAP_TYPE_NAME.put(type, name);
    }

    private static void addType(String type, MapKeyType typeBean) {
        MAP_VAR_LOAD_TYPE_MAP.put(type, typeBean);
    }

}